package com.hsnn.medstgmini.pro.base.dao.Impl;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.pro.base.dao.BaseCompDao;
import com.hsnn.medstgmini.pro.base.model.form.CompForm;
import com.hsnn.medstgmini.util.AreaUtil;
import com.hsnn.medstgmini.util.Pagination;

/**
 * @category 企业目录查看
 * @author 蔡春龙
 * @date 2015年11月12日
 */
@Repository
public class BaseCompDaoImpl implements BaseCompDao {

	@Autowired
	private HibernateSqlUtil dao;
	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory;

	/**
	 * @category 中心查看生产企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getScListByZX(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");
		sb.append(" SELECT DISTINCT comp_code FROM bid_projdrugs WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() ");
		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");
		
		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}
	
	   
	   //生产企业更新
	   public void basegoodsitem  (StdCompinfo compinfo)  throws FileNotFoundException {
		 
		 Session session = sessionFactory.openSession();
			String sql = "update base_goods_item set prod_compname=:prodCompName,prod_compname_short=:prodCompnameShort,prod_compname_spel=:prodCompnameSpel where  prod_compcode=:prodCompCode ";
			Query aquery =  session.createSQLQuery(sql.toString());
			aquery.setParameter("prodCompName", compinfo.getCompName());
			aquery.setParameter("prodCompCode", compinfo.getCompCode());
			aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
			aquery.setParameter("prodCompnameShort", compinfo.getCompShortName());
			aquery.executeUpdate();
			session.clear();
			session.close();
	    }
	   
	   @Override
	   public void basegoodsitemCat  (StdCompinfo compinfo)  throws FileNotFoundException {
			 
			 Session session = sessionFactory.openSession();
				String sql = "update base_goods_item set cat_comp_name=:prodCompName,cat_comp_name_short=:prodCompnameShort,cat_comp_name_spel=:prodCompnameSpel where  cat_comp_code=:prodCompCode ";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.setParameter("prodCompnameShort", compinfo.getCompShortName());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	   
	   public void basegoodsitemLog  (StdCompinfo compinfo)  throws FileNotFoundException {
			 
			 Session session = sessionFactory.openSession();
				String sql = "insert into base_goods_item_log select uuid(),t.* from base_goods_item t where prod_compcode=:prodCompCode or cat_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	   
	    public void purorderinfo  (StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update pur_orderinfo set prod_compname=:prodCompName,prod_compname_spel=:prodCompnameSpel where  prod_compcode=:prodCompCode  ";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	    
	    
	    public void  puraoginfo (StdCompinfo compinfo)  throws FileNotFoundException{
			
			 Session session = sessionFactory.openSession();
				String sql = "update pur_aoginfo set prod_compname=:prodcompname,prod_compname_spel=:prodCompnameSpel where  prod_compcode=:prodCompcode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodcompname", compinfo.getCompName());
				aquery.setParameter("prodCompcode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	    
	       
	    
	    public void  stdproddruginfo (StdCompinfo compinfo)  throws FileNotFoundException{
			
			 Session session = sessionFactory.openSession();
				String sql = "update std_proddruginfo set comp_name=:CompName,comp_name_spel=:CompnameSpel where  comp_code=:CompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("CompName", compinfo.getCompName());
				aquery.setParameter("CompCode", compinfo.getCompCode());
				aquery.setParameter("CompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void  anahospitalprodcompdrugmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_hospital_prodcompdrug_mon set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void  anahospitalprodcompdrug(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_hospital_prodcompdrug  set prod_comp_name=:prodCompName,prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	   
	    
	    public void  anahospitalprodcomp(StdCompinfo compinfo)  throws FileNotFoundException{
			
			 Session session = sessionFactory.openSession();
				String sql = "update ana_hospital_prodcomp  set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
			 
	    }
	    
	    public void  anahospitalprodcompmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			    Session session = sessionFactory.openSession();
				String sql = "update ana_hospital_prodcomp_mon  set prod_comp_name=:prodCompName,prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    
	    public void anaprodcompinfoarea(StdCompinfo compinfo)  throws FileNotFoundException{
			
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompinfo_area set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
			 
			 
	    }
	    
	    public void anaprodcompinfoareamon(StdCompinfo compinfo)  throws FileNotFoundException{
			
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompinfo_area_mon  set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
			 
	    }
	    
	    public void anaprodcompdruginfoarea(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompdruginfo_area  set prod_comp_name=:prodCompName ,prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    	
	    public void anaprodcompdruginfoareamon(StdCompinfo compinfo)  throws FileNotFoundException{
			
			    Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompdruginfo_area_mon set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anaproddruginfototal(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_proddruginfo_total set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anaproddruginfototalmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_proddruginfo_total_mon set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    
	    
	    
	    
	    
	    public void anacomplprodcompareadrug(StdCompinfo compinfo)  throws FileNotFoundException{
			 
			 
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_area_drug set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anacomplprodcompareadrugmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_area_drug_mon set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	  
	    
	    
	    public void anacomplprodcomparea(StdCompinfo compinfo)  throws FileNotFoundException{
			    Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_area  set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anacomplprodcompareamon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_area_mon set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
			 
	    } 
	  
	    public void anacomplprodcompdrug(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_drug set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    
	    public void anacomplprodcompdrugmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_drug_mon set prod_comp_name=:prodCompName,prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	   
	    public void anacomplprodcomp(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp set prod_comp_name=:prodCompName,prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anacomplprodcompmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_mon set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompNameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anaprodcompinfosea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompinfo_sea set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anaprodcompinfoyear(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompinfo_year set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	   
	    public void anaprodcompinfo(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompinfo  set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anaprodcompinfomon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_prodcompinfo_mon  set prod_comp_name=:prodCompName, prod_comp_name_spel=:prodCompnameSpel where  prod_comp_code=:prodCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("prodCompName", compinfo.getCompName());
				aquery.setParameter("prodCompCode", compinfo.getCompCode());
				aquery.setParameter("prodCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    
	    
	    //配送企业更新
	    public void anacomplprodcompmonDel(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp_mon set del_comp_name=:delCompName, del_comp_name_spel=:delCompnameSpel where  del_comp_code=:delCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    
	    public void anacomplprodcompDel(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update ana_compl_prodcomp set del_comp_name=:delCompName, del_comp_name_spel=:delCompNameSpel where  del_comp_code=:delCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    
	    public void anacomplprodcompareaDel(StdCompinfo compinfo)  throws FileNotFoundException{
		    Session session = sessionFactory.openSession();
			String sql = "update ana_compl_prodcomp_area  set del_comp_name=:delCompName, del_comp_name_spel=:delCompnameSpel where  del_comp_code=:delCompCode";
			Query aquery =  session.createSQLQuery(sql.toString());
			aquery.setParameter("delCompName", compinfo.getCompName());
			aquery.setParameter("delCompCode", compinfo.getCompCode());
			aquery.setParameter("delCompnameSpel", compinfo.getCompSpelCode());
			aquery.executeUpdate();
			session.clear();
			session.close();
    }
	    
	    
	    
	    public void  puraoginfoDel (StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update pur_aoginfo set del_comp_name=:delCompName, del_comp_name_spel=:delCompnameSpel where  del_comp_code=:delCompCode";
				Query aquery =  session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompnameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	    
	    
	    public void anaPurDateDel(StdCompinfo compinfo)  throws FileNotFoundException{
			 	Session session = sessionFactory.openSession();
				String sql = " update  ana_pur_date set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompinfoMon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_mon set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompinfoYear(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_year set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompinfosea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_sea set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompinfo(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaDeldruginfoTotalMon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_deldruginfo_total_mon set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaDeldruginfoTotal(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "update  ana_deldruginfo_total set del_comp_name=:delCompName, del_comp_name_spel=:delCompNameSpel where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    public void anaDeldruginfoTotalYear(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_deldruginfo_total_year set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    public void anaDeldruginfoTotalSea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_deldruginfo_total_sea set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompdruginfoAreaMon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compdruginfo_area_mon set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompdruginfoArea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compdruginfo_area set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    public void anaCompdruginfoAreYear(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compdruginfo_area_year set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompdruginfoAreaSea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compdruginfo_area_sea set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompinfoAreaMon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_area_mon set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anaCompinfoArea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_area set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    public void anaCompinfoAreaYear(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_area_year set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    
	    public void anaCompinfoAreaSea(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  ana_compinfo_area_sea set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void baseShortage(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update  base_shortage set  del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void  purreturnplan (StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update pur_returnplan  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel  where del_comp_code = :delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	   
	    
	    
	   
	    public void  basedelrelationship (StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update base_delrelationship  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	    @Override
	    public void  basedelrelationshipLog (StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = "insert into base_delrelationship_log select uuid(),t.* from base_delrelationship t where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
		    }
	  
	    public void  anahospitalcompdrug(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update ana_hospital_compdrug  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void  anahospitalcompdrugmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update ana_hospital_compdrug_mon  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anahospitalcomp(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update ana_hospital_comp  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anahospitalcompmon(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
				String sql = " update ana_hospital_comp_mon  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    }
	    
	    public void anacomplprodcompareadrugps(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
			 	String sql = " update ana_compl_prodcomp_area_drug  set del_comp_name=:delCompName, del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anacomplprodcompareadrugmonps(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
			 	String sql = " update ana_compl_prodcomp_area_drug_mon  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anacomplprodcompareamonps(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
			 	String sql = " update ana_compl_prodcomp_area_mon  set del_comp_name=:delCompName, del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    public void anacomplprodcompdrugps(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
			 	String sql = " update ana_compl_prodcomp_drug  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	  
	    public void anacomplprodcompdrugmonps(StdCompinfo compinfo)  throws FileNotFoundException{
			 Session session = sessionFactory.openSession();
			 	String sql = " update ana_compl_prodcomp_drug_mon  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
				Query aquery = session.createSQLQuery(sql.toString());
				aquery.setParameter("delCompName", compinfo.getCompName());
				aquery.setParameter("delCompCode", compinfo.getCompCode());
				aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
				aquery.executeUpdate();
				session.clear();
				session.close();
	    } 
	    
	    
	    
	    
	    
	    
	/**
	 * @category 医疗机构查看生产企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getScListByYY(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");

		sb.append(" SELECT DISTINCT a.comp_code FROM bid_projdrugs a JOIN ( ");
		sb.append(" SELECT proj_id FROM bid_projhospital WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() AND hosp_code = :hospCode ");
		sb.append(" ) b ON a.proj_id = b.proj_id ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			params.put("hospCode", compForm.getHospCode());
			
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}
	
	/**
	 * @category 生产企业查看生产企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getScListBySC(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");

		sb.append(" SELECT DISTINCT a.comp_code FROM bid_projdrugs a JOIN ( ");
		sb.append(" SELECT DISTINCT proj_id FROM bid_projdrugs WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() AND comp_code = :curCompCode ");
		sb.append(" ) b ON a.proj_id = b.proj_id ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			params.put("curCompCode", compForm.getCurCompCode());
			
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}
	
	/**
	 * @category 配送企业查看生产企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getScListByPS(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");
		
		sb.append(" SELECT DISTINCT a.comp_code FROM bid_projdrugs a JOIN ( ");
		sb.append(" SELECT DISTINCT proj_id FROM bid_projcompany WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() AND comp_code = :curCompCode ");
		sb.append(" ) b ON a.proj_id = b.proj_id ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			params.put("curCompCode", compForm.getCurCompCode());
			
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}
	
	/**
	 * @category 中心查看配送企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getPsListByZX(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");
		
		sb.append(" SELECT DISTINCT comp_code FROM bid_projcompany WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}

	/**
	 * @category 医疗机构查看配送企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getPsListByYY(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");
		
		sb.append(" SELECT DISTINCT comp_code FROM bid_projcompany a JOIN ( ");
		sb.append(" SELECT DISTINCT proj_id FROM bid_projhospital WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() AND hosp_code = :hospCode ");
		sb.append(" ) b ON a.proj_id = b.proj_id ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			params.put("hospCode", compForm.getHospCode());
			
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}

	/**
	 * @category 生产企业查看配送企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getPsListBySC(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");
		
		sb.append(" SELECT DISTINCT comp_code FROM bid_projcompany a JOIN ( ");
		sb.append(" SELECT DISTINCT proj_id FROM bid_projdrugs WHERE  proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() AND comp_code = :curCompCode ");
		sb.append(" ) b ON a.proj_id = b.proj_id ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			params.put("curCompCode", compForm.getCurCompCode());
			
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}

	/**
	 * @category 配送企业查看配送企业目录
	 * @date 2015年11月12日
	 * @param page
	 * @return
	 */
	public Pagination getPsListByPS(Pagination page) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT a.comp_id compId, a.comp_code compCode, a.comp_name compName, ");
		sb.append(" a.area_id areaId, c.area_name areaName, a.comp_reg_id regId, d.comp_reg_name regName, ");
		sb.append(" a.org_code orgCode, a.comp_group_id groupId, e.comp_group_name groupName ");
		sb.append(" FROM std_compinfo a JOIN ( ");
		
		sb.append(" SELECT DISTINCT comp_code FROM bid_projcompany a JOIN ( ");
		sb.append(" SELECT DISTINCT proj_id FROM bid_projcompany WHERE proj_status = 1 AND `status` = 1 ");
		sb.append(" AND proj_starttime <= SYSDATE() AND proj_endtime >= SYSDATE() AND comp_code = :curCompCode ");
		sb.append(" ) b ON a.proj_id = b.proj_id ");

		sb.append(" ) b ON a.comp_code = b.comp_code ");
		sb.append(" LEFT JOIN dic_area c ON a.area_id = c.area_id ");
		sb.append(" LEFT JOIN dic_comptype d ON a.comp_reg_id = d.comp_reg_id ");
		sb.append(" LEFT JOIN std_compgroup e ON a.comp_group_id = e.comp_group_id ");
		sb.append(" WHERE a.`status` = 1 ");

		CompForm compForm = (CompForm) page.getForm();
		Map<String, Object> params = new HashMap<String, Object>();

		if (compForm != null) {
			params.put("curCompCode", compForm.getCurCompCode());
			
			if (StringUtils.isNotBlank(compForm.getCompName())) {
				sb.append(" AND (a.comp_name LIKE :compName OR a.comp_spel_code LIKE :compName) ");
				params.put("compName", "%" + compForm.getCompName() + "%");
			}
			if (StringUtils.isNotBlank(compForm.getCompCode())) {
				sb.append(" AND a.comp_code = :compCode ");
				params.put("compCode", compForm.getCompCode());
			}
			if (StringUtils.isNotBlank(compForm.getRegId())) {
				sb.append(" AND a.comp_reg_id = :regId ");
				params.put("regId", compForm.getRegId());
			}
			if (StringUtils.isNotBlank(compForm.getAreaId())) {
				sb.append(" AND a.area_id LIKE :areaId ");
				params.put("areaId",
						AreaUtil.escapeAreaId(compForm.getAreaId()));
			}
		}

		dao.getPageMapList(sb.toString(), params, page);

		return page;
	}


	@Override
	public void anacompinfoarea(StdCompinfo compinfo)
			throws FileNotFoundException {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void anacompdruginfoarea(StdCompinfo compinfo)
			throws FileNotFoundException {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void anadeldruginfototal(StdCompinfo compinfo)
			throws FileNotFoundException {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void sysUser(StdCompinfo compinfo){
		Session session = sessionFactory.openSession();
		String sql = "update sys_user set name=:prodCompName where  org_id = :compId";
		Query aquery =  session.createSQLQuery(sql.toString());
		aquery.setParameter("prodCompName", compinfo.getCompName());
		aquery.setParameter("compId", compinfo.getCompId());
		aquery.executeUpdate();
		session.clear();
		session.close();
	}
	
	@Override
	public void sysUserLog(StdCompinfo compinfo)  throws FileNotFoundException{
		Session session = sessionFactory.openSession();
		String sql = "insert into sys_user_log select uuid(),t.* from sys_user t where org_id = :compId";
		Query aquery =  session.createSQLQuery(sql.toString());
		aquery.setParameter("compId", compinfo.getCompId());
		aquery.executeUpdate();
		session.clear();
		session.close();
	}
	
	@Override
	 public void  baseDelAreaRel (StdCompinfo compinfo)  throws FileNotFoundException{
		 Session session = sessionFactory.openSession();
			String sql = " update base_delrelationship  set del_comp_name=:delCompName,del_comp_name_spel=:delCompNameSpel where del_comp_code=:delCompCode ";
			Query aquery = session.createSQLQuery(sql.toString());
			aquery.setParameter("delCompName", compinfo.getCompName());
			aquery.setParameter("delCompCode", compinfo.getCompCode());
			aquery.setParameter("delCompNameSpel", compinfo.getCompSpelCode());
			aquery.executeUpdate();
			session.clear();
			session.close();
	    }

}
